/*-------------------------------------------------------------------------
   cc_compat.h - support both keil and sdcc

   Copyright (C) 2010 One Laptop per Child

   This program is free software; you can redistribute it and/or modify it
   under the terms of the GNU General Public License as published by the
   Free Software Foundation; either version 2, or (at your option) any
   later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

   In other words, you are welcome to use, share and improve this program.
   You are forbidden to forbid anyone else to use, share and improve
   what you give them.   Help stamp out software-hoarding!

   As a special exception, you may use this file as part of a free software
   library for the XO of the One Laptop per Child project without restriction.
   Specifically, if other files instantiate
   templates or use macros or inline functions from this file, or you compile
   this file and link it with other files to produce an executable, this
   file does not by itself cause the resulting executable to be covered by
   the GNU General Public License.  This exception does not however
   invalidate any other reasons why the executable file might be covered by
   the GNU General Public License.
-------------------------------------------------------------------------*/

#ifndef _CC_COMPAT_H
#define _CC_COMPAT_H 1

#if defined(SDCC)

#define code __code
#define xdata __xdata
#define interrupt __interrupt

#define BootBlock 0
#define sfr_at(id, where) sfr __at where id
#define sbit_at(id, where) sbit __at where id
#define EXTERN_INTERRUPT(no) __interrupt(no)
#define data __data  /* maybe */

#define bool __bit

#ifdef ALLOCATE_EXTERNS
#define EXTERN /* nothing */
#define ABS_ADDR(id, where) __at where id
#define ABS_SBIT(id, where, bit)  __sbit  __at(where+bit) id
#define ABS_SFR(id, where)        __sfr   __at(where) id
#define ABS_SFRX(id, where)			__xdata volatile unsigned char __at(where) id

#else
#define EXTERN extern
#define ABS_ADDR(id, where) __at where id
#define ABS_SBIT(id, where, bit)  __sbit  __at(where+bit) id
#define ABS_SFR(id, where)        __sfr   __at(where) id
#define ABS_SFRX(id, where)			__xdata volatile unsigned char __at(where) id
#endif

#define OPT_PRAGMA 0

#define PUTS(val)	do{puts(val);putchar('\r');}while(0)

#else /* not SDCC -- Keil */

#define sfr_at(id, where) sfr id = where
#define sbit_at(id, where) sbit id = where
#define INTERRUPT(no) interrupt no
#define EXTERN_INTERRUPT(no)

#ifdef ALLOCATE_EXTERNS
#define EXTERN /* nothing */
#define ABS_ADDR(id, where) id _at_ where
#define ABS_SBIT(id, where, bit)	sbit  id = where^bit
#define ABS_SFR(id, where)			sfr   id = where
#define ABS_SFRX(id, where)			volatile unsigned char xdata id _at_ where
#else
#define EXTERN extern
#define ABS_ADDR(id, where) id
#define ABS_SBIT(id, where, bit)	sbit  id = where^bit
#define ABS_SFR(id, where)			sfr   id = where
#define ABS_SFRX(id, where)			extern volatile unsigned char xdata id
#endif

#define bool unsigned char
#define __code code
#define __xdata xdata
#define __idata idata
#define __data data
#define __pdata pdata


#define OPT_PRAGMA 1

#define PUTS(val)	do{puts(val);}while(0)

#include <intrins.h>    // for _nop_()

#define LJMP_WORKAROUND 1

#endif /* USE_SDCC */

typedef unsigned int uint;

#endif // _CC_COMPAT_H

#define USE_KB3700 0
